/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchBillingMore.java
 *
 * Created on Aug 7, 2012, 2:41:26 PM
 */

package Model.dialog;

import DataBase.DBManagerment;
import Processing.PikaDate;
import java.sql.Connection;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class dlgFilterStock extends javax.swing.JDialog {

    /** Creates new form SearchBillingMore */
    public dlgFilterStock(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btgPaid = new javax.swing.ButtonGroup();
        pnlCenter = new javax.swing.JPanel();
        cbbStockThan1 = new javax.swing.JComboBox();
        cbbStockThan2 = new javax.swing.JComboBox();
        txtStock1 = new javax.swing.JTextField();
        txtStock2 = new javax.swing.JTextField();
        cbbCost = new javax.swing.JCheckBox();
        cbbINu = new javax.swing.JCheckBox();
        cbbDNu = new javax.swing.JCheckBox();
        txtStockINum2 = new javax.swing.JTextField();
        txtStockINum1 = new javax.swing.JTextField();
        cbbStockINum2 = new javax.swing.JComboBox();
        cbbStockINum1 = new javax.swing.JComboBox();
        cbbStockDNum1 = new javax.swing.JComboBox();
        txtStockDNum2 = new javax.swing.JTextField();
        txtStockDNum1 = new javax.swing.JTextField();
        cbbStockDNum2 = new javax.swing.JComboBox();
        pnlBootom = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Filter Stock");
        setResizable(false);

        cbbStockThan1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", ">", ">=", "<", "<=" }));
        cbbStockThan1.setEnabled(false);
        cbbStockThan1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockThan1ItemStateChanged(evt);
            }
        });

        cbbStockThan2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "<", "<=" }));
        cbbStockThan2.setEnabled(false);
        cbbStockThan2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockThan2ItemStateChanged(evt);
            }
        });

        txtStock1.setEnabled(false);

        txtStock2.setEnabled(false);

        cbbCost.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        cbbCost.setText("                        Cost:");
        cbbCost.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cbbCostStateChanged(evt);
            }
        });

        cbbINu.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        cbbINu.setText("   Items available:");
        cbbINu.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cbbINuStateChanged(evt);
            }
        });

        cbbDNu.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        cbbDNu.setText(" Items consumed:");
        cbbDNu.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cbbDNuStateChanged(evt);
            }
        });

        txtStockINum2.setEnabled(false);

        txtStockINum1.setEnabled(false);

        cbbStockINum2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "<", "<=" }));
        cbbStockINum2.setEnabled(false);
        cbbStockINum2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockINum2ItemStateChanged(evt);
            }
        });

        cbbStockINum1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", ">", ">=", "<", "<=" }));
        cbbStockINum1.setEnabled(false);
        cbbStockINum1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockINum1ItemStateChanged(evt);
            }
        });

        cbbStockDNum1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "=", ">", ">=", "<", "<=" }));
        cbbStockDNum1.setEnabled(false);
        cbbStockDNum1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockDNum1ItemStateChanged(evt);
            }
        });

        txtStockDNum2.setEnabled(false);

        txtStockDNum1.setEnabled(false);

        cbbStockDNum2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No", "<", "<=" }));
        cbbStockDNum2.setEnabled(false);
        cbbStockDNum2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbbStockDNum2ItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout pnlCenterLayout = new javax.swing.GroupLayout(pnlCenter);
        pnlCenter.setLayout(pnlCenterLayout);
        pnlCenterLayout.setHorizontalGroup(
            pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCenterLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlCenterLayout.createSequentialGroup()
                        .addComponent(cbbCost)
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cbbStockThan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbbStockThan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtStock2)
                            .addComponent(txtStock1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlCenterLayout.createSequentialGroup()
                        .addComponent(cbbINu)
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cbbStockINum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbbStockINum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtStockINum2)
                            .addComponent(txtStockINum1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pnlCenterLayout.createSequentialGroup()
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cbbStockDNum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(pnlCenterLayout.createSequentialGroup()
                                .addComponent(cbbDNu)
                                .addGap(18, 18, 18)
                                .addComponent(cbbStockDNum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtStockDNum2)
                            .addComponent(txtStockDNum1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        pnlCenterLayout.setVerticalGroup(
            pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCenterLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbbCost)
                    .addGroup(pnlCenterLayout.createSequentialGroup()
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockThan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStock1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockThan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStock2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlCenterLayout.createSequentialGroup()
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockINum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStockINum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockINum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStockINum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockDNum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStockDNum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbbDNu))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlCenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStockDNum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtStockDNum2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(cbbINu))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        getContentPane().add(pnlCenter, java.awt.BorderLayout.CENTER);

        pnlBootom.setPreferredSize(new java.awt.Dimension(226, 50));

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBootomLayout = new javax.swing.GroupLayout(pnlBootom);
        pnlBootom.setLayout(pnlBootomLayout);
        pnlBootomLayout.setHorizontalGroup(
            pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBootomLayout.createSequentialGroup()
                .addGap(85, 85, 85)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addContainerGap(85, Short.MAX_VALUE))
        );
        pnlBootomLayout.setVerticalGroup(
            pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBootomLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBootomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getContentPane().add(pnlBootom, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbbStockThan1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockThan1ItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            if (cbbStockThan1.getSelectedItem().equals("=") || cbbStockThan1.getSelectedItem().equals("<") || cbbStockThan1.getSelectedItem().equals("<=")) {
                cbbStockThan2.setEnabled(false);

                cbbStockThan2.setSelectedItem("No");
            }else{
                cbbStockThan2.setEnabled(true);
            }
        }
    }//GEN-LAST:event_cbbStockThan1ItemStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:        

        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        list = new ArrayList<String>();

        if (cbbCost.isSelected()) {
            if (cbbStockThan1.getSelectedItem().equals("=")) {
                // Lấy một chuỗi dạng: "[Cost] = 10"
                String search = "[Cost] = " + txtStock1.getText();

                list.add(search);

            } else if (cbbStockThan1.getSelectedItem().equals("<")) {
                // Lấy một chuỗi dạng: "[Cost] < 10'"
                String search = "[Cost] < " + txtStock1.getText();

                list.add(search);

            } else if (cbbStockThan1.getSelectedItem().equals("<=")) {
                // Lấy một chuỗi dạng: "[Cost] <= 10"
                String search = "[Cost] <= " + txtStock1.getText();

                list.add(search);

            } else if (cbbStockThan1.getSelectedItem().equals(">")) {
                // Lấy một chuỗi dạng: "[Cost] > 10"
                String search = "[Cost] > " + txtStock1.getText();

                list.add(search);

                if (cbbStockThan2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Cost] > " + txtStock1.getText() + " and " + "[Cost] < " + txtStock2.getText();

                    list.add(search);

                } else if (cbbStockThan2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Cost] > " + txtStock1.getText() + " and " + "[Cost] <= " + txtStock2.getText();

                    list.add(search);

                }
            } else if (cbbStockThan1.getSelectedItem().equals(">=")) {
                // Lấy một chuỗi dạng: "[Cost] > '2012-7-8'" với ngày tháng lấy từ combobox
                String search = "[Cost] >= " + txtStock1.getText();

                list.add(search);
                if (cbbStockThan2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Cost] >= " + txtStock1.getText() + " and " + "[Cost] < " + txtStock2.getText();

                    list.add(search);

                } else if (cbbStockThan2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Cost] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Cost] >= " + txtStock1.getText() + " and " + "[Cost] <= " + txtStock2.getText();

                    list.add(search);
                }
            }
        }

        if (cbbINu.isSelected()) {
            if (cbbStockINum1.getSelectedItem().equals("=")) {
                // Lấy một chuỗi dạng: "[Items Available] = 10"
                String search = "[Items Available] = " + txtStockINum1.getText();

                list.add(search);

            } else if (cbbStockINum1.getSelectedItem().equals("<")) {
                // Lấy một chuỗi dạng: "[Items Available] < 10'"
                String search = "[Items Available] < " + txtStockINum1.getText();

                list.add(search);

            } else if (cbbStockINum1.getSelectedItem().equals("<=")) {
                // Lấy một chuỗi dạng: "[Items Available] <= 10"
                String search = "[Items Available] <= " + txtStockINum1.getText();

                list.add(search);

            } else if (cbbStockINum1.getSelectedItem().equals(">")) {
                // Lấy một chuỗi dạng: "[Items Available] > 10"
                String search = "[Items Available] > " + txtStockINum1.getText();

                list.add(search);

                if (cbbStockINum2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] > " + txtStockINum1.getText() + " and " + "[Items Available] < " + txtStockINum2.getText();

                    list.add(search);

                } else if (cbbStockINum2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] > " + txtStockINum1.getText() + " and " + "[Items Available] <= " + txtStockINum2.getText();

                    list.add(search);

                }
            } else if (cbbStockINum1.getSelectedItem().equals(">=")) {
                // Lấy một chuỗi dạng: "[Items Available] > '2012-7-8'" với ngày tháng lấy từ combobox
                String search = "[Items Available] >= " + txtStockINum1.getText();

                list.add(search);
                if (cbbStockINum2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] >= " + txtStockINum1.getText() + " and " + "[Items Available] < " + txtStockINum2.getText();

                    list.add(search);

                } else if (cbbStockINum2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] >= " + txtStockINum1.getText() + " and " + "[Items Available] <= " + txtStockINum2.getText();

                    list.add(search);
                }
            }
        }

        if (cbbDNu.isSelected()) {
            if (cbbStockDNum1.getSelectedItem().equals("=")) {
                // Lấy một chuỗi dạng: "[Items Available] = 10"
                String search = "[Items Available] = " + txtStockDNum1.getText();

                list.add(search);

            } else if (cbbStockDNum1.getSelectedItem().equals("<")) {
                // Lấy một chuỗi dạng: "[Items Available] < 10'"
                String search = "[Items Available] < " + txtStockDNum1.getText();

                list.add(search);

            } else if (cbbStockDNum1.getSelectedItem().equals("<=")) {
                // Lấy một chuỗi dạng: "[Items Available] <= 10"
                String search = "[Items Available] <= " + txtStockDNum1.getText();

                list.add(search);

            } else if (cbbStockDNum1.getSelectedItem().equals(">")) {
                // Lấy một chuỗi dạng: "[Items Available] > 10"
                String search = "[Items Available] > " + txtStockDNum1.getText();

                list.add(search);

                if (cbbStockDNum2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] > " + txtStockDNum1.getText() + " and " + "[Items Available] < " + txtStockDNum2.getText();

                    list.add(search);

                } else if (cbbStockDNum2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] > " + txtStockDNum1.getText() + " and " + "[Items Available] <= " + txtStockDNum2.getText();

                    list.add(search);

                }
            } else if (cbbStockDNum1.getSelectedItem().equals(">=")) {
                // Lấy một chuỗi dạng: "[Items Available] > '2012-7-8'" với ngày tháng lấy từ combobox
                String search = "[Items Available] >= " + txtStockDNum1.getText();

                list.add(search);
                if (cbbStockDNum2.getSelectedItem().equals("<")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] >= " + txtStockDNum1.getText() + " and " + "[Items Available] < " + txtStockDNum2.getText();

                    list.add(search);

                } else if (cbbStockDNum2.getSelectedItem().equals("<=")) {
                    // Lấy một chuỗi dạng: "[Items Available] <= '2012-7-8'" với ngày tháng lấy từ combobox
                    search = "[Items Available] >= " + txtStockDNum1.getText() + " and " + "[Items Available] <= " + txtStockDNum2.getText();

                    list.add(search);
                }
            }
        }
        
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cbbStockINum1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockINum1ItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            if (cbbStockINum1.getSelectedItem().equals("=") || cbbStockINum1.getSelectedItem().equals("<") || cbbStockINum1.getSelectedItem().equals("<=")) {
                cbbStockINum2.setEnabled(false);

                cbbStockINum2.setSelectedItem("No");
            }else{
                cbbStockINum2.setEnabled(true);
            }
        }
    }//GEN-LAST:event_cbbStockINum1ItemStateChanged

    private void cbbStockDNum1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockDNum1ItemStateChanged
        // TODO add your handling code here:
        if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
            if (cbbStockDNum1.getSelectedItem().equals("=") || cbbStockDNum1.getSelectedItem().equals("<") || cbbStockDNum1.getSelectedItem().equals("<=")) {
                cbbStockDNum2.setEnabled(false);

                cbbStockDNum2.setSelectedItem("No");
            }else{
                cbbStockDNum2.setEnabled(true);
            }
        }
    }//GEN-LAST:event_cbbStockDNum1ItemStateChanged

    private void cbbCostStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbbCostStateChanged
        // TODO add your handling code here:
        if (cbbCost.isSelected()) {
            cbbStockThan1.setEnabled(true);
            txtStock1.setEnabled(true);
        }else{
            cbbStockThan1.setEnabled(false);
            txtStock1.setEnabled(false);
        }
    }//GEN-LAST:event_cbbCostStateChanged

    private void cbbStockThan2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockThan2ItemStateChanged
        // TODO add your handling code here:
        if (!cbbStockThan2.getSelectedItem().equals("No")) {
            txtStock2.setEnabled(true);

        }else{
            txtStock2.setEnabled(false);
        }
    }//GEN-LAST:event_cbbStockThan2ItemStateChanged

    private void cbbINuStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbbINuStateChanged
        // TODO add your handling code here:
        if (cbbINu.isSelected()) {
            cbbStockINum1.setEnabled(true);
            txtStockINum1.setEnabled(true);
        }else{
            cbbStockINum1.setEnabled(false);
            txtStockINum1.setEnabled(false);
        }
    }//GEN-LAST:event_cbbINuStateChanged

    private void cbbStockINum2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockINum2ItemStateChanged
        // TODO add your handling code here:
        if (!cbbStockINum2.getSelectedItem().equals("No")) {
            txtStockINum2.setEnabled(true);

        }else{
            txtStockINum2.setEnabled(false);
        }
    }//GEN-LAST:event_cbbStockINum2ItemStateChanged

    private void cbbDNuStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbbDNuStateChanged
        // TODO add your handling code here:
        if (cbbDNu.isSelected()) {
            cbbStockDNum1.setEnabled(true);
            txtStockDNum1.setEnabled(true);
        }else{
            cbbStockDNum1.setEnabled(false);
            txtStockDNum1.setEnabled(false);
        }
    }//GEN-LAST:event_cbbDNuStateChanged

    private void cbbStockDNum2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbbStockDNum2ItemStateChanged
        // TODO add your handling code here:
        if (!cbbStockDNum2.getSelectedItem().equals("No")) {
            txtStockDNum2.setEnabled(true);

        }else{
            txtStockDNum2.setEnabled(false);
        }
    }//GEN-LAST:event_cbbStockDNum2ItemStateChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgFilterStock dialog = new dlgFilterStock(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    /**
     * Đây là list chứa chuỗi tìm kiếm
     */
    private ArrayList<String> list = null;

    /**
     * Method này trả về list chuỗi tìm kiếm
     * @return list chuỗi tìm kiếm
     */
    public ArrayList<String> getList() {
        return list;
    }

    private DBManagerment db = new DBManagerment();
    private Connection conn;


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btgPaid;
    private javax.swing.JCheckBox cbbCost;
    private javax.swing.JCheckBox cbbDNu;
    private javax.swing.JCheckBox cbbINu;
    private javax.swing.JComboBox cbbStockDNum1;
    private javax.swing.JComboBox cbbStockDNum2;
    private javax.swing.JComboBox cbbStockINum1;
    private javax.swing.JComboBox cbbStockINum2;
    private javax.swing.JComboBox cbbStockThan1;
    private javax.swing.JComboBox cbbStockThan2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel pnlBootom;
    private javax.swing.JPanel pnlCenter;
    private javax.swing.JTextField txtStock1;
    private javax.swing.JTextField txtStock2;
    private javax.swing.JTextField txtStockDNum1;
    private javax.swing.JTextField txtStockDNum2;
    private javax.swing.JTextField txtStockINum1;
    private javax.swing.JTextField txtStockINum2;
    // End of variables declaration//GEN-END:variables

}
